<?php
  include ('header.php');
?>
<head>
<title><?php echo $titles['site_config']?></title>
</head>

<body>
<?php

if($_SESSION['access']<3)
{
DIE('Помилка: Ви не маєте права доступу до сату:');
}

if ($_GET[del]){
$sql="DELETE FROM admin_config where id='".$_GET[del]."'";  
$process=mysql_query($sql, $db);
}



if (isset($_POST['edit_full_config']) && $_POST['edit_full_config']) {
for ($n = 1; $n <= $_SESSION["count_par"]; $n++) {
$id="id".$n;
$config_name="config_name".$n;
$config_description="config_description".$n;
$config_size="config_size".$n;
$config_value="config_value".$n;
$sql="update admin_config set config_name='".$_POST[$config_name]."',
config_description='".$_POST[$config_description]."', 
config_size='".$_POST[$config_size]."', 
config_value='".$_POST[$config_value]."' where  id='".$_POST[$id]."'";
$process=mysql_query($sql, $db);
//echo $sql."<br>";
}
$_SESSION[config_name_add]=$_POST[config_name_add];
if (isset($_SESSION[config_name_add]) && isset($_POST[config_description_add]) && isset($_POST[config_size_add]) 
&& $_SESSION[config_name_add] && $_POST[config_description_add] && $_POST[config_size_add] )
{

$sql="insert into admin_config  (config_name,config_description,config_size,config_value) 
values ('".$_SESSION[config_name_add]."','".$_POST[config_description_add]."','".$_POST[config_size_add]."','".$_POST[config_value_add]."')";
$process=mysql_query($sql, $db);
$_SESSION[config_name_add]=0;
unset ($_SESSION[config_name_add]);


}
}
?>
<form name="edit_config"  method="POST">
<table class="IND_INVENTORY" width=50%>
<tr>

    <td class="IND_INVENTORY_C" >ID</td>
	<td class="IND_INVENTORY_C">Назва конфігурації</td>
	<td class="IND_INVENTORY_C">Призначення</td>
	<td class="IND_INVENTORY_C">Розмір ність</td>
	<td class="IND_INVENTORY_C">Значення</td>
	<td class="IND_INVENTORY_C">Дія</td>

</tr>
<?php
$sql="select * from admin_config";  
$process=mysql_query($sql, $db);
$i=1;
$j=0;
while ($row = mysql_fetch_array($process, $i)){
$j++;
	echo "<tr>";
	echo " <td class=\"IND_INVENTORY_C\" ><input type=hidden  name='id".$j."' value='".$row[id]."'>".$row[id]."</td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_name".$j."' value='".$row[config_name]."' size=20></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_description".$j."' value='".$row[config_description]."' size=60></td>";
	echo "<td class=\"IND_INVENTORY_C\" width=5><input type=text  name='config_size".$j."' value='".$row[config_size]."' size=6></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_value".$j."' value='".$row[config_value]."' size=30></td>";
	echo "<td class=\"IND_INVENTORY_C\"><a href='".$_SERVER['PHP_SELF']."?del=".$row[id]."' onClick=\"return confirm('".$messages[config_name_delete].$row[config_name]."?');\"><img src=images/delete.png	border=0  width=20 height=20 onMouseOver=\"toolTip('".$actions['delete']."')\" onMouseOut=\"toolTip()\"></img></a></td>";
	echo "</tr>";
}
$_SESSION["count_par"]=$j;
echo "<tr>";
	echo " <td class=\"IND_INVENTORY_C\" ><input type=hidden  name='id_add'>+</td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_name_add'  size=20></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_description_add'  size=60></td>";
	echo "<td class=\"IND_INVENTORY_C\" width=5><input type=text  name='config_size_add'  size=6></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='config_value_add'  size=30></td>";
	echo "<td class=\"IND_INVENTORY_C\"></td>";
	echo "</tr><div id=\"floatTip\"></div>";
?>
<tr><td colspan="6" ><input type="submit" value="<?php echo $texts[save] ?>" name="edit_full_config"></td></tr>
</table>

</form>
</body>
<?php
  include ('footer.php');
?>